package com.diet.web.controller.diet;

import com.diet.common.core.controller.BaseController;
import com.diet.common.core.domain.AjaxResult;
import com.diet.system.service.IDietUserService;
import com.diet.system.service.IDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据统计Controller
 */
@RestController
@RequestMapping("/diet/statistics")
public class DietStatisticsController extends BaseController
{
    @Autowired
    private IDietUserService dietUserService;

    @Autowired
    private IDishService dishService;

    /**
     * 获取系统统计数据
     */
    @GetMapping("/system")
    public AjaxResult getSystemStatistics()
    {
        Map<String, Object> data = new HashMap<>();
        data.put("totalUsers", 1250);
        data.put("totalDishes", 856);
        data.put("totalIngredients", 324);
        data.put("yesterdayLoginUsers", dietUserService.selectYesterdayLoginUsers());
        return AjaxResult.success(data);
    }

    /**
     * 获取用户分布统计
     */
    @GetMapping("/user/distribution")
    public AjaxResult getUserDistribution()
    {
        Map<String, Object> data = new HashMap<>();
        List<Map<String, Object>> genderData = dietUserService.selectUserGenderDistribution();
        data.put("gender", genderData);
        List<Map<String, Object>> ageData = dietUserService.selectUserAgeDistribution();
        data.put("age", ageData);
        return AjaxResult.success(data);
    }

    /**
     * 获取菜品热度统计
     */
    @GetMapping("/dish/hot")
    public AjaxResult getDishHotStatistics()
    {
        List<Map<String, Object>> data = dishService.selectDishHotTop6();
        return AjaxResult.success(data);
    }

    /**
     * 获取菜品评分统计
     */
    @GetMapping("/dish/rating")
    public AjaxResult getDishRatingStatistics()
    {
        List<Map<String, Object>> data = dishService.selectDishRatingTop6();
        return AjaxResult.success(data);
    }

    /**
     * 获取菜系分布统计
     */
    @GetMapping("/cuisine/distribution")
    public AjaxResult getCuisineDistribution()
    {
        List<Map<String, Object>> data = dishService.selectCuisineDistribution();
        return AjaxResult.success(data);
    }
}